package justForFun;
import java.io.BufferedReader;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public final class AccessTextFile {

    /**
     * read a .txt text to a  StringBuffer
     * @throws IOException
     */
    public void readToBuffer(StringBuffer buffer, InputStream is)throws IOException {
        
    	String line;        // to save the content of every line
        char c;
        int carLu;
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        
        carLu = reader.read();

	     do{
	        	buffer.append((char)carLu);
	        	carLu=reader.read(); 
	        }
	        while(carLu!=-1);
/*       
        do{
        	buffer.append((char)carLu);
        	carLu = reader.read();
        }
        while(carLu!=-1);
 */      

        /*
        line = reader.readLine();       // read the first line
        while (line != null) {          // if line == null,  finished 
            buffer.append(line);        // add the content to buffer
            buffer.append("\n");        // add \n
            line = reader.readLine();   // next line
        }
        */
        
        /*
        c = (char)reader.read();
        
        while(c!='@'){

			buffer.append(c);
        	c = (char)reader.read();
        }
*/


    }

    public static void main(String[] args) throws IOException {

        AccessTextFile test = new AccessTextFile();

        InputStream is = new FileInputStream("t1.txt");
        StringBuffer buffer = new StringBuffer();
        test.readToBuffer(buffer, is);
        System.out.println(buffer);     // output
        is.close();

    }

}
